var ad_width = "100px";
var ad_height = "250px";
var ad_img = "images/ad1.jpg";
var ad_bo_img =  "images/ad2.jpg";
var close_img = "images/close.png";


/**创建广告容器的div */
var ad_left = document.createElement( "div");
ad_left.style.width = ad_width;
ad_left.style.height = ad_height;
ad_left.style.padding = "0px" ;
ad_left.style.position = "absolute";

ad_left.style.float = "left";

ad_left.style.left = "30px";
ad_left.style.top = "20px";

var adimg = document.createElement( "img" );
adimg.src = ad_img;
ad_left.appendChild(adimg);

/**创建广告关闭按钮 */
var closeimg = document.createElement( "img" );
closeimg.src = close_img;
closeimg.style.width = "50px" ;
closeimg.style.position="relative";
closeimg.style.left="50px";
closeimg.style.top="-20px";
closeimg.style.cursor = "pointer";
ad_left.appendChild(closeimg);

document.documentElement.appendChild(ad_left);

closeimg.addEventListener("click" ,function( ){
    ad_left.style.display = "none";
    });
    

window.addEventListener( "scroll", function( ) {
        var st1 = document.documentElement.scrollTop || document. body. scrollTop;ad_left.style.top = (st1 + 20) + "px";
        });
   
        
//右边广告
var ad_right = document.createElement( "div");
ad_right.style.width = ad_width;
ad_right.style.height = ad_height;
ad_right.style.padding = "0px" ;
ad_right.style.position = "absolute";

ad_right.style.float = "right";

ad_right.style.right = "30px";
ad_right.style.top = "20px";

var adimg1 = document.createElement( "img" );
adimg1.src = ad_img;
ad_right.appendChild(adimg1);

/**创建广告关闭按钮 */
var closeimg1 = document.createElement( "img" );
closeimg1.src = close_img;
closeimg1.style.width = "50px" ;
closeimg1.style.position="relative";
closeimg1.style.left="50px";
closeimg1.style.top="-20px";
closeimg1.style.cursor = "pointer";
ad_right.appendChild(closeimg1);

document.documentElement.appendChild(ad_right);

closeimg1.addEventListener("click" ,function( ){
    ad_right.style.display = "none";
    });

    window.addEventListener( "scroll", function( ) {
        var st1 = document.documentElement.scrollTop || document. body. scrollTop;ad_right.style.top = (st1 + 20) + "px";
        });

       
//下面的广告

/**创建广告容器的div */
var ad_bottom = document.createElement( "div");
ad_bottom.style.width = "500px";
ad_bottom.style.height = "300px";
ad_bottom.style.padding = "0px" ;
ad_bottom.style.position = "absolute";
ad_bottom.style.top = "700px";

ad_bottom.style.right = "50px";

var adimg2 = document.createElement( "img" );
adimg2.src =ad_bo_img;
adimg2.style.width = "498px";
adimg2.style.position = "fixed";//不随滚轮的滑动而滑动

ad_bottom.appendChild(adimg2);

document.documentElement.appendChild(ad_bottom);
console.log(ad_bottom.offsetTop);


setInterval(function(){
    if(ad_bottom.offsetTop > 250){
        ad_bottom.style.top = parseInt(ad_bottom.style.top)-10+"px";
    }
},100);